MySQL WHERE Clause


MySQL WHERE Clause is used with SELECT, INSERT, UPDATE and DELETE clause to filter the results. It specifies a specific position where you have to do the operation.



Syntax


WHERE conditions;

Example


SELECT * FROM officers WHERE address = 'Mau';






MySQL Distinct Clause


MySQL DISTINCT clause is used to remove duplicate records from the table and fetch only the unique records. The DISTINCT clause is only used with the SELECT statement.



Syntax


SELECT DISTINCT expressions FROM tables [WHERE conditions];

Example


SELECT DISTINCT address FROM officers;






MySQL order by Clause


Order By Clause -:



The Order By Keyword Is Used To Sort The Result-Set In Ascending Or Descending Order. The Order By Keyword Sorts The Records In Ascending Order By Default. To Sort The Records In Descending Order, Use The Desc Keyword.

Syntax:-



SELECT column1, column2, ... FROM table_name ORDER BY column1, column2, ... ASC|DESC;

Example :-





MySQL group by Clause



The GROUP BY statement groups rows that have the same values into summary rows, like "find the number of customers in each country". The GROUP BY statement is often used with aggregate functions (COUNT(), MAX(), MIN(), SUM(), AVG()) to group the result-set by one or more columns.



Syntax-:

SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s) ORDER BY column_name(s);

Example -:







MySQL having clause


HAVING Clause -:



HAVING clause was added to SQL because the WHERE keyword cannot be used with aggregate functions.

Syntax-:



SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s) HAVING condition ORDER BY column_name(s);

Example -: